#include "LeJeux.h"

// LeJeux.
#include "GameStateMachine.h"
#include "GameStateInit.h"
#include "GameStateUpdate.h"
#include "GameStateExit.h"

// GameEngine.
#include "Binding.h"
#include "InputManager.h"

// Renderer.
#include "Renderer.h"

// CoreLib.
#include <StartupStruct.h>

lj::LeJeux::LeJeux()
: le::App()
, m_GameStateMachine(NULL)
{

}

lj::LeJeux::~LeJeux()
{

}

bool lj::LeJeux::Init(le::StartupStruct& startupStruct)
{
	if(le::App::Init(startupStruct))
	{
		le::Binding::_SdmInit();

		le::Binding* binding = le::Binding::GetInstance();
		binding->CreateBindings(startupStruct);

		m_GameStateMachine = new GameStateMachine();
		m_GameStateMachine->AddGameState(new GameStateInit());
		m_GameStateMachine->AddGameState(new GameStateUpdate());
		m_GameStateMachine->AddGameState(new GameStateExit());
		m_GameStateMachine->SwitchToGameState(eGameState_Init);
		m_GameStateMachine->QueueGameState(eGameState_Update);
		return true;
	}
	return false;
}

void lj::LeJeux::Update()
{
	m_GameStateMachine->Update();
}

void lj::LeJeux::Terminate()
{
	le::Binding::_SdmShutDown();
}

void lj::LeJeux::OnScreenResize( uint32 /*width*/, uint32 /*height*/ )
{

}

void lj::LeJeux::OnInputEvent( const SDL_Event& event )
{
	le::Binding::GetInstance()->GetInputManager()->OnInputEvent(event);
}
